package action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.bo.AccountManagerBO;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import form.RegistrationForm;

/** 
 * Action Class ExampleXMLAction
 */
public class RegistrationAction extends Action {

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
		
		RegistrationForm registry = (RegistrationForm) form;
		HttpSession  session = request.getSession(true);
		String userName = registry.getUserName();
//		String password = registry.getPassWord();
//		String firstName = registry.getFirstName();
//		String lastName = registry.getLastName();
//		int gender = registry.getGender();
//		Time dOB = registry.getDateOfBirth();
//		String emailAddr = registry.getEmailAddr();
		String avatar = registry.getAvatar();
//		int deleted = 0;
		
		AccountManagerBO accountManagerBO = new AccountManagerBO();
		if(!accountManagerBO.CheckUser(userName)){
			accountManagerBO.Registration(registry);
			session.setAttribute("userName", userName);
//			session.setAttribute("password", password);
			session.setAttribute("avatar", avatar);
			request.setAttribute("notifi", "You have successfully registered!");
			return mapping.findForward("OK");
		}
		request.setAttribute("notifi", "The UserName was in existence.!");
		return mapping.findForward("NOK");
	}

}